package com.framework.plm.dbs.orm.impl;

import com.framework.plm.dbs.orm.IDialect;

public class SQLServerDialect implements IDialect {

	public SQLServerDialect() {
    }

    public String getPagedString(String sql, boolean hasOffset) {
        return null;
    }

    public String getPagedString(String sql, int offset, int limit) {
        if(offset > 0) {
            throw new UnsupportedOperationException("sql server has no offset");
        } else {
            return (new StringBuffer(sql.length() + 8)).append(sql).insert(getAfterSelectInsertPoint(sql), " top " + limit).toString();
        }
    }

    static int getAfterSelectInsertPoint(String sql) {
        int selectIndex = sql.toLowerCase().indexOf("select");
        int selectDistinctIndex = sql.toLowerCase().indexOf("select distinct");
        return selectIndex + (selectDistinctIndex != selectIndex ? 6 : 15);
    }

    public boolean supportsPaged() {
        return false;
    }

}
